/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.geaSV.beans;

import com.geaSV.conexiones.conectarBD;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;


/**
 *
 * @author vash
 */
@ManagedBean
@RequestScoped
public class reportes {

    /**
     * Creates a new instance of reportes
     */
    public reportes() {
    }
    
          public StreamedContent getArchivoPDF() throws JRException {
 
Connection conn = conectarBD.conectar();
   
InputStream inputStream = null;

try{
 
ByteArrayOutputStream Teste = new ByteArrayOutputStream();
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(getClass().getClassLoader().getResourceAsStream("/reportes/EmpleadosTodos.jasper"));
 
JasperPrint print = JasperFillManager.fillReport(jasperReport, null,conn);
 
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
 
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, Teste);
 
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
 
exporter.exportReport();
 
inputStream = new ByteArrayInputStream(Teste.toByteArray());
 
}catch(JRException ex) {
    System.out.println("este error reporte"+ex.getMessage());
}
 
return new DefaultStreamedContent(inputStream,"application/pdf","ReporteEmpleados");
 
}
}
